package com.spring.tools;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoList {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()){

            test4(jedis);
        }
    }



    public static void test(Jedis jedis){

        System.out.println("lpush和lrange");
        jedis.flushAll();

        jedis.lpush("key","111","222","333");

        List<String> result = jedis.lrange("key", 0, -1);
        System.out.println(result);

    }
    public static void test2(Jedis jedis){

        System.out.println("rpush");
        jedis.flushAll();

        jedis.rpush("key","111","222","333");

        List<String> result = jedis.lrange("key", 0, -1);
        System.out.println(result);

    }

    public static void test3(Jedis jedis){

        System.out.println("lpop");
        jedis.flushAll();

        jedis.rpush("key","111","222","333");

        String result = jedis.lpop("key");
        System.out.println(result);

         result = jedis.lpop("key");
        System.out.println(result);

        result = jedis.lpop("key");
        System.out.println(result);

        result = jedis.lpop("key");
        System.out.println(result);


    }

    public static void test4(Jedis jedis){

        System.out.println("rpop");
        jedis.flushAll();

        jedis.rpush("key","111","222","333");

        String result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);


    }

    public static void test5(Jedis jedis){

        System.out.println("bloop");
        jedis.flushAll();

        List<String> results = jedis.blpop(100,"key");
        System.out.println("results[0]:" + results.get(0));
        System.out.println("results[1]:"+results.get(1));

    }
    public static void test6(Jedis jedis){

        System.out.println("llen");
        jedis.flushAll();

        jedis.rpush("key","111","222","333");

        long len = jedis.llen("key");
        System.out.println("len:"+len);

    }




}
